package com.changgou.web.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;
/**
 * @author Sherlock
 * @date 2020/3/16
 */
@Service
public class AuthServiceImpl implements AuthService{

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 查看cookie中jti是否存在
     * @param request
     * @return
     */
    @Override
    public String getJtiFromCookie(ServerHttpRequest request) {
        //获取cookie对象
        HttpCookie cookie = request.getCookies().getFirst("jti");
        if (cookie!=null){
            return cookie.getValue();
        }
        return null;
    }

    /**
     * 查看redis中的token是否过期或者存在
     * @param jti
     * @return
     */
    @Override
    public String getTokenFromRedis(String jti) {
        String token = redisTemplate.boundValueOps(jti).get();
        return token;
    }
}
